package com.example.test.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.test.R;
import com.example.test.entity.Goods;

import java.util.List;

public class HomeAdapter extends RecyclerView.Adapter<HomeAdapter.ViewHolder> {
    private List<Goods> goodsItems ;
    private View.OnClickListener onClickListener ;
    public HomeAdapter(List<Goods> goods ){
        this.goodsItems = goods ;

    }
    public void setGoodsItem(List<Goods> goods){
        this.goodsItems = goods ;
    }

    @NonNull
    @Override
    public HomeAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.home_item , parent , false) ;
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull HomeAdapter.ViewHolder holder, int position) {
        Goods goods = goodsItems.get(position);
        holder.homeItemName.setText(goods.getGoodsName());
        holder.homeItemPrice.setText(goods.getGoodsPrice().toString());
    }

    @Override
    public int getItemCount() {
        return goodsItems.size();
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {
        TextView homeItemName , homeItemPrice ;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            homeItemName = itemView.findViewById(R.id.home_item_name);
            homeItemPrice = itemView.findViewById(R.id.home_item_price);
        }
    }
}
